Vue.component('item-block', {
    props:['data'],
    methods:{
        chooseTo (data)
        {
            data = encodeURI(data)

            if (location.href.endsWith('/'))
                location.href += data
            else
                location.href += '/' + data
        }
    },
    template:
    `
    <div>
        <h1 @click="chooseTo(data.name)"> {{ data.name }} </h1>
        <hr/>
    </div>
    `
});

window.onload = ()=>{
    let main1 = new Vue({
        el : '#main',
        data:{
            fileList:[],
            isRootURL:false
        },
        compute:{

        },
        methods:{
            getFileList : function(){
                var that = this
                that.$http({
                    method:"GET",
                    url: document.URL + '/'
                }).then(function(data){
                    that.fileList = data.body;
                    that.fileList.sort((a,b)=>a.name.localeCompare(b.name));
                })
            },
            back : function(){
                window.location.pathname = window.location.pathname.split('/').slice(0,-1).join('/');
            }
        },
        created:function(){
            this.getFileList();
            this.isRootURL = window.location.pathname === '/';
        }
    });
}